Success

data class Success<out T>(val value: T) : Try<T>

Constructors

Link copied to clipboard
fun <out T> Success(value: T)

Functions

Link copied to clipboard
open override fun filter(predicate: (T) -> Boolean): Try<T>

Returns the same Success if the predicate is satisfied for the value. Otherwise returns a Failure.

Link copied to clipboard
inline fun <R> filterIsInstance(): Try<R>

Returns the same Success casted to type R if it is R. Otherwise returns a Failure.

Link copied to clipboard
open override fun filterNot(predicate: (T) -> Boolean): Try<T>

Returns the same Success if the predicate is not satisfied for the value. Otherwise returns a Failure.

Link copied to clipboard
open override fun filterOrElse(predicate: (T) -> Boolean, throwable: (T) -> Throwable): Try<T>

Returns the same Success if the predicate is satisfied for the value. Otherwise returns a Failure containing the given throwable.

Link copied to clipboard
open override fun <R> flatMap(transform: (T) -> Try<R>): Try<R>

Maps value of a Success to a new Try using transform or returns the same Try if this is a Failure.

Link copied to clipboard
inline fun <R> fold(successTransform: (T) -> R, failureTransform: (Throwable) -> R): R

Transforms a Success using successTransform or a Failure using failureTransform.

Link copied to clipboard
open override fun forEach(action: (T) -> Unit)

Runs action if this is a Success. Returns Unit without any action if this is a Failure.

Link copied to clipboard
open override fun get(): T

Gets the value of a Success or throw an exception from a Failure.

Link copied to clipboard
open override fun getOrNull(): T?

Gets the value of a Success or null if this is a Failure.

Link copied to clipboard
open override fun <R> map(transform: (T) -> R): Try<R>

Maps value of a Success using transform or returns the same Try if this is a Failure.

Link copied to clipboard
open override fun toEither(): Either<Throwable, T>

Converts this Try to Either.

Link copied to clipboard
open override fun toOption(): Option<T>

Converts this Try to Option.

Link copied to clipboard
inline fun <R> transform(successTransform: (T) -> Try<R>, failureTransform: (Throwable) -> Try<R>): Try<R>

Transforms a Success using successTransform or a Failure using failureTransform.

Link copied to clipboard
infix fun <R> zip(other: Try<R>): Try<Pair<T, R>>

Returns Success containing a Pair of values of this and other if both instances of Try are Success. Otherwise returns first Failure.

inline fun <T1, R> zip(other: Try<T1>, transform: (T, T1) -> R): Try<R>

Returns Success containing the result of applying transform to both values of this and other if both instances of Try are Success. Otherwise returns first Failure.

Properties

Link copied to clipboard
open override val failed: Try<Throwable>

Returns a Success with an exception it this is a Failure or a Failure if this is a Success.

Link copied to clipboard
open override val isFailure: Boolean

Returns true if this is a Failure or false if this is Success.

Link copied to clipboard
open override val isSuccess: Boolean

Returns true if this is a Success or false if this is Failure.

Link copied to clipboard
val value: T